package com.zeng.jiudian.servlet.productType;

import com.alibaba.fastjson.JSONObject;
import com.zeng.jiudian.service.ProductTypeService;
import com.zeng.jiudian.service.impl.ProductTypeServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author JJ_yo
 * @Date 2020/8/12 - 17:31
 */
@WebServlet("/back/productType/del")
public class ProductTypeDelServlet extends HttpServlet
{
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        //处理乱码
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("application/json;charset=utf-8");

        String idString = req.getParameter("id");
        int id = (idString == null || "".equals(idString) ? 0 : Integer.parseInt(idString));

        ProductTypeService service = new ProductTypeServiceImpl();
        int count = service.delete(id);

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("count", count);
        resp.getWriter().println(jsonObject);
    }
}
